import {Component} from 'react';
import {
  Group,
  TextareaField,
  TextField,
} from 'saltui';
import DB from "../../../app/db";
import {
  urlPrefix,
  URLS,
  nodataIcon,
  dictMap
} from '../../../app/variables';
export default class PageHome extends Component {
  constructor(props) {
    super(props);

    this.state = {
      id: props.params.boardId ? props.params.boardId : '',
      name: '',
      replyCount: 0,
      postCount: 0,
      boardAuthor: '',
      description:'',
    }
    dd.biz.navigation.setTitle({
          title: '详情',
        onSuccess: function (result) {
        },
         onFail: function () {
          }
        });
  }

  componentDidMount() {
    this.getBoardInfo();
  }
getBoardInfo(){
  let param = {
        id: this.state.id
      };
      DB.ForumModuleAPI.getBoardInfo(param).then((content) => {
        var description = "";
        if(content.description == null||content.description ==''){
          description = "暂无描述";
        }else{
          description = content.description;
        }

          this.setState({
            name:content.name,
            replyCount:content.replyCount,
            postCount:content.postCount,
            boardAuthor:content.moderator,
            description:description
          });

        
      }).catch((error) => {
        Toast.show({
          type: 'error',
          content: error.errorMsg,
        });
      });     
}

  render() {
    let t = this;
    return (
      <div>
          <Group>
            <Group.List>
              <TextField required readOnly={true} label="版块名称" value={t.state.name}/>
            </Group.List>
            <Group.List>
              <TextField required readOnly={true} label="主题数" value={t.state.postCount}/>
            </Group.List>
            <Group.List>
              <TextField required readOnly={true} label="评论数" value={t.state.replyCount}/>
            </Group.List>
            <Group.List>
              <TextField required readOnly={true} label="版主" value={t.state.boardAuthor}/>
            </Group.List>
            <Group.List>
            <TextField  readOnly={true} label="描述" value={t.state.description}/>
            </Group.List>
          </Group>
      </div>
    );
  }
}
